<?php
function clientHWADDR() {
/** Always check that the user running apache can execute arp. **/
$ARP = '/sbin/arp';//FC
// $ARP = '/usr/sbin/arp';//normal
//
$remoteIp = $_SERVER['REMOTE_ADDR'];
$arpTable = exec("$ARP -a {$remoteIp}");
$arpSplitted = split("\n",$arpTable);
  if ($remoteIp == '127.0.0.1') {
//     echo "You cannot obtain the mac from localhost";
  } else {
    if (eregi($remoteIp,$arpSplitted[0])) {
      if (preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$arpSplitted[0],$matches)) {
return $matches[0];
} else {
//   echo "<p>Mac Address Regex Failing</p>";
}
} else {
//   echo "Arp entry not found for your computer.";
}
return false;
}
}
function HWADDRfromDHCPACK($line) {
   if (preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$line,$matches)) {
return $matches[0];
} else {
return null;
}
}
function dateFromDHCPlogLine ($line) {
  if (preg_match('/^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20(\d{1,2})\x20(\d{2}:\d{2}:\d{2})\x20/',$line,$matches) ) {
    return $matches[0];
  } else if (preg_match('/^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20\x20(\d{1})\x20(\d{2}:\d{2}:\d{2})\x20/',$line,$matches) ) {
    return $matches[0];
  } else {
    return null;
  }
}
?>
